#ifndef __RTDEBUG_H__
#define __RTDEBUG_H__  //当你觉得太压抑时,就出去转一转吧??
#include <rtconfig.h>

/*setting depend check*/
#ifdef  RT_USING_POSIX  //下面这两个宏都要定义
#if !defined(RT_USING_DFS) || !defined(RT_USING_DFS_DEVFS)
#error "POSIX poll/select,stdin need file system(RT_USING_DFS) and device file system(RT_USING_DFS_DEVFS)"
#endif

#if defined(RT_USING_LWIP) && !defined(RT_USING_DFS_NET)  //使用LWIP但没有使用DFS_NET
#error "POSIX poll/select,stdin need file BSD socket API(RT_USING_DFS_NET)"
#endif

#if !defined(RT_USING_LIBC)   //没有定义RT_USING_LIBC
#error "POSIX layer need standard C library(RT_USING_LIBC)"
#endif
#endif

#ifdef  RT_USING_POSIX_TERMIOS
#if !defined(RT_USING_POSIX)  //没有定义RT_USING_POSIX
#error "termios need POSIX layer(RT_USING_POSIX)"
#endif
#endif

/*Using this macro to control all kernel debug features*/
#ifdef  RT_DEBUG
/*turn on some of these (set to non-zero) to debug kernel*/
#ifndef RT_DEBUG_MEM
#define RT_DEBUG_MEM                0
#endif

#ifndef RT_DEBUG_MEMHEAP
#define RT_DEBUG_MEMHEAP            0 
#endif

#ifndef RT_DEBUG_MODULE          
#define RT_DEBUG_MODULE             0   
#endif

#ifndef RT_DEBUG_SCHEDULER          
#define RT_DEBUG_SCHEDULER          0  //scheduler
#endif

#ifndef RT_DEBUG_SLAB
#define RT_DEBUG_SLAB               0
#endif

#ifndef RT_DEBUG_THREAD
#define RT_DEBUG_THREAD             0 
#endif

#ifndef RT_DEBUG_TIMER              
#define RT_DEBUG_TIMER              0
#endif

#ifndef RT_DEBUG_IRQ
#define RT_DEBUG_IRQ                0
#endif

#ifndef RT_DEBUG_IPC
#define RT_DEBUG_IPC                0
#endif

#ifndef RT_DEBUG_INIT
#define RT_DEBUG_INIT               0 
#endif

/*Turn on this to enable context check*/
#ifndef RT_DEBUG_CONTEXT_CHECK
#define RT_DEBUG_CONTEXT_CHECK      1
#endif

#define RT_DEBUG_LOG(type,message)                          \
do                                                          \
{                                                           \
    if(type)                                                \
    {                                                       \
        rt_kprintf(" "message);                             \  //是这样写的吗？？
    }                                                       \
} while (0)   //说明后面得加一个;号

#define RT_ASSERT(EX)                                       \
if(!(EX))                                                   \
{                                                           \
    rt_assert_handler(#EX,__FUNCTION__,__LINE__);           \
}

/*Macro to check current context*/
#if RT_DEBUG_CONTEXT_CHECK 
#define RT_DEBUG_NOT_IN_INTERRUPT                           \
do                                                          \
{                                                           \
    rt_base_t level;                                        \ //long
    level=rt_hw_interrupt_disable();                        \
    if(rt_interrupt_get_nest()!=0)                          \
    {  /*这个函数好像没见过呀  */                             \
        rt_kprintf("Function[%s] shall not be used in ISR\n",__FUNCTION__); \
        RT_ASSERT(0)                                        \
    }                                                       \
    rt_hw_interrupt_enable(level);                          \
}                                                           \
while(0)

/**
 * “In thread context” means:
 *  1) the scheduler has been started
 *  2) not in interrupt context.
 */
#define RT_DEBUG_IN_THREAD_CONTEXT                          \
do                                                          \
{                                                           \
    rt_base_t level;                                        \
    level=rt_hw_interrupt_disable();                        \
    if(rt_thread_self()==RT_NULL)                           \
    {                                                       \
        rt_kprintf("Function[%s] shall not be used before scheduler start\n",\
                    __FUNCTION__);                          \
        RT_ASSERT(0)                                        \
    }                                                       \
    RT_DEBUG_NOT_IN_INTERRUPT;                              \
    rt_hw_interrupt_enable(level);                          \
}                                                           \
while(0)
#else   /*RT_DEBUG_CONTEXT_CHECK*/  //否则就什么也不做
#define RT_DEBUG_NOT_IN_INTERRUPT
#define RT_DEBUG_IN_THREAD_CONTEXT
#endif  /*RT_DEBUG_CONTEXT_CHECK*/

#else       /*RT_DEBUG*/
/*上面是使用了DEBUG  这里是没有使用DEBUG*/
#define     RT_ASSERT(EX)

#define     RT_DEBUG_LOG(type,message)
#define     RT_DEBUG_NOT_IN_INTERRUPT
#define     RT_DEBUG_IN_THREAD_CONTEXT

#endif      /*RT_DEBUG*/

#endif      /*__RTDEBUG_H__*/